package com.a2j.web.car.controller;

import com.a2j.beans.base.BaseBean;
import com.a2j.beans.base.code.ResponseCode;
import com.a2j.beans.car.CarSpecification;
import com.a2j.web.car.service.CarSpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: bzb
 * Data: 2021/10/30 22:23
 * Desc: 车规
 */
@RestController
@RequestMapping ("car")
@Api(tags = "车规")
public class CarSpecController {

    @Resource
    CarSpecService service;

    /**
     * 添加车规
     * @param carSpec 车规信息
     */
    @PostMapping("addCarSpec")
    @ApiOperation(value = "添加车规")
    @ApiImplicitParams({})
    public BaseBean<String> addCarSpec(@RequestBody CarSpecification carSpec) {
        service.addCarSpec(carSpec);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 获取所有车规列表
     */
    @GetMapping("getAllCarSpecs")
    @ApiOperation(value = "查询所有车规列表")
    public BaseBean<List<CarSpecification>> getAllCarSpecs() {
        return service.getAllCarSpecs();
    }

    /**
     * 获取车规详情
     * @param id 车规id
     */
    @GetMapping("getCarSpecDetail/{id}")
    @ApiOperation(value = "查询车规详情")
    @ApiImplicitParam(name = "id", value = "车规id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<CarSpecification> getCarSpecDetail(@PathVariable  Integer id) {
        return service.getCarSpecDetail(id);
    }

    /**
     * 删除车规
     * @param id 车规id
     */
    @DeleteMapping("deleteCarSpec/{id}")
    @ApiOperation(value = "删除车规")
    @ApiImplicitParam(name = "id", value = "车规id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<String> deleteCarSpec(@PathVariable Integer id) {
        service.deleteCarSpec(id);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 更新车规信息
     * @param carSpec 车规信息
     */
    @PutMapping("updateCarSpec")
    @ApiOperation(value = "更新车规信息")
    @ApiImplicitParams({})
    public BaseBean<String> updateCarSpec(@RequestBody CarSpecification carSpec) {
        service.updateCarSpec(carSpec);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 车规开关
     * @param id 车规id
     * @param enable 开关状态  0:关 1:开
     */
    @PutMapping("enable")
    @ApiOperation(value = "车规开关")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "车规id", dataType = "int", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "enable", value = "开关状态  0:关 1:开", dataType = "int", defaultValue = "0")
    })
    public BaseBean<String> enable(@RequestParam Integer id, @RequestParam Integer enable) {
        service.enable(id, enable);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

}
